

const __api = require('../../utils/api.js');
const App = getApp()

Page({
  data: {
    userInfo: {},
    //hasUserInfo: false,

    //二维码
    QRcode: {
      icon: '../../image/my/u1488.png',
      path: '/pages/address/list/index'
    },
    moneys: [
      {
        num: '500.00',
        text: '零钱',
        path: '/pages/my/cash/cash'
      },
      {
        num: '200',
        text: '金币',
        path: '/pages/my/goldcoin/goldcoin'
      },
    ],


    items: [
      {
        icon: '../../image/my/u1524.png',
        text: '收货地址',
        path: '/pages/address/list/index'
      },
      {
        icon: '../../image/my/u2965.png',
        text: '我的收藏',
        path: '/pages/my/collection/list',
      },
      {
        icon: '../../image/my/u1514.png',
        text: '关于我们',
        path: '/pages/my/aboutUs/aboutUs'
      },
    ],


  },




  //去二维码页面
  toQRcode(e) {
    console.log(e)
    var ll = e.currentTarget.dataset.id
    //App.WxService.navigateTo('/pages/my/qrcode/qrcode')

    console.log("ll>>>>>>>>>>>>>"+ll)

    wx.navigateTo({
      url: '/pages/my/qrcode/qrcode',
    });

  },




  onLoad() {
    this.getUserInfo()
    //this.getStorageInfo()
  },


  navigateTo(e) {
    const index = e.currentTarget.dataset.index
    const path = e.currentTarget.dataset.path

    //switch(index) {
    //	case 2:
    //		App.WxService.makePhoneCall({
    //			phoneNumber: path
    //		})
    //		break
    //	default:

    //App.WxService.navigateTo(path)

    wx.navigateTo({
      url: path,
    });



    //}
  },








  /**
   * 
   * 
  getUserInfo() {
    const userInfo = App.globalData.userInfo

  if (userInfo) {
    this.setData({
      userInfo: userInfo
    })
    return
  },

  
  App.getUserInfo()
  .then(data => {
          console.log(data)
    this.setData({
      userInfo: data
    })
  })
  },

  */



  //luyou

  getUserInfo: function () {
    var that = this
    if (App.globalData.hasLogin === false) {
      wx.login({
        success: _getUserInfo
      })
    } else {

      console.log("222222222222222222222222222222222");

      _getUserInfo()
    }



    function _getUserInfo() {
      wx.getUserInfo({
        success: function (res) {
          that.setData({
            hasUserInfo: true,
            userInfo: res.userInfo
          })
          that.update()
        }
      })
    }
  },

  //luyou end

  /** 
  getStorageInfo() {
    App.WxService.getStorageInfo()
    .then(data => {
      console.log(data)
      this.setData({
        'settings[0].path': `${data.currentSize}KB`
      })
    })
  },
  */

  bindtap(e) {
    const index = e.currentTarget.dataset.index
    const path = e.currentTarget.dataset.path

    switch (index) {
      case 0:
        App.WxService.showModal({
          title: '友情提示',
          content: '确定要清除缓存吗？',
        })
          .then(data => data.confirm == 1 && App.WxService.clearStorage())
        break
      default:
        App.WxService.navigateTo(path)
    }
  },
  logout() {
    App.WxService.showModal({
      title: '友情提示',
      content: '确定要登出吗？',
    })
      .then(data => data.confirm == 1 && this.signOut())
  },
  signOut() {
    App.HttpService.signOut()
      .then(res => {
        const data = res.data
        console.log(data)
        if (data.meta.code == 0) {
          App.WxService.removeStorageSync('token')
          App.WxService.redirectTo('/pages/login/index')
        }
      })
  },
})